<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="18">
        <el-form   label-width="80px" :model="formLabelAlign">
          <el-form-item label="名称">
            <el-input v-model="formLabelAlign.name"></el-input>
          </el-form-item>
          <el-form-item label="上课地址">
            <el-input v-model="formLabelAlign.place"></el-input>
          </el-form-item>
          <el-form-item label="管理教师">
            <el-select v-model="formLabelAlign.mtid" placeholder="请选择">
              <el-option
                v-for="item in teacherlist"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开课时间">
            <el-date-picker
              v-model="formLabelAlign.starttime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
           </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker
              v-model="formLabelAlign.endtime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item  label="课表">
            <el-table
              :data="formLabelAlign.kebiao"
              border
              style="width: 100%">
              <el-table-column
                label="周一"
                width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.Monday"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                label="周二"
                width="150">

                <template slot-scope="scope">
                  <el-input v-model="scope.row.Tuesday"></el-input>
                </template>
              </el-table-column>

              <el-table-column
                label="周三"
                width="150">

                <template slot-scope="scope">
                  <el-input v-model="scope.row.Wednesday"></el-input>
                </template>
              </el-table-column>

              <el-table-column
                label="周四"
                width="150">

                <template slot-scope="scope">
                  <el-input v-model="scope.row.Thursday"></el-input>
                </template>
              </el-table-column>

              <el-table-column
                label="周五"
                width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.Friday"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                label="周六"
                width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.Saturday"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                label="周日"
                width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.Sunday"></el-input>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item label="操作">
            <el-button class="el-button--success" @click="doadd">添加</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { addClassroom ,getAllTeacher } from "@/api/admin";
import { Message } from '_element-ui@2.3.4@element-ui'

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      teacherlist:[],
      formLabelAlign:{
        kebiao:[
          {
            Monday:"",
            Tuesday:"",
            Wednesday:"",
            Thursday:"",
            Friday:"",
            Saturday:"",
            Sunday:"",
          }, {
            Monday:"",
            Tuesday:"",
            Wednesday:"",
            Thursday:"",
            Friday:"",
            Saturday:"",
            Sunday:"",
          }, {
            Monday:"",
            Tuesday:"",
            Wednesday:"",
            Thursday:"",
            Friday:"",
            Saturday:"",
            Sunday:"",
          }, {
            Monday:"",
            Tuesday:"",
            Wednesday:"",
            Thursday:"",
            Friday:"",
            Saturday:"",
            Sunday:"",
          }, {
            Monday:"",
            Tuesday:"",
            Wednesday:"",
            Thursday:"",
            Friday:"",
            Saturday:"",
            Sunday:"",
          }, {
            Monday:"",
            Tuesday:"",
            Wednesday:"",
            Thursday:"",
            Friday:"",
            Saturday:"",
            Sunday:"",
          },
        ]
      },
      classroomlist:[]
    };
  },

  created() {
    this.getteacher();
  },
  methods: {
    getteacher(){
      getAllTeacher().then(res=>{
        this.teacherlist = res.info;
      })
    },
    doadd() {

      if(this.formLabelAlign.name == undefined || this.formLabelAlign.name == "")
      {
        this.$notify({
          title: '兄弟',
          message: '名称没写呢',
          type: 'error'
        });
        return ;
      }     if(this.formLabelAlign.place == undefined || this.formLabelAlign.place == "")
      {
        this.$notify({
          title: '兄弟',
          message: '上课地址！',
          type: 'error'
        });
        return ;
      }     if(this.formLabelAlign.mtid == undefined || this.formLabelAlign.mtid == "")
      {
        this.$notify({
          title: '兄弟',
          message: '班主任是谁呀？',
          type: 'error'
        });
        return ;
      }  if(this.formLabelAlign.starttime == undefined || this.formLabelAlign.starttime == "")
      {
        this.$notify({
          title: '兄弟',
          message: '开课时间',
          type: 'error'
        });
        return ;
      }if(this.formLabelAlign.endtime == undefined || this.formLabelAlign.endtime == "")
      {
        this.$notify({
          title: '兄弟',
          message: '结束时间',
          type: 'error'
        });
        return ;
      }if(this.formLabelAlign.kebiao == undefined || this.formLabelAlign.kebiao == "")
      {
        this.$notify({
          title: '兄弟',
          message: '课表没写呢',
          type: 'error'
        });
        return ;
      }

      this.listLoading = true;
      var additem =  {};
      Object.assign(additem,this.formLabelAlign)
      additem.kebiao =  JSON.stringify(additem.kebiao)
      addClassroom(additem).then((response) => {

        this.$notify({
          title: '成功',
          message: '添加成功！',
          type: 'success'
        });

        this.listLoading = false;
      }).catch(err=>{
        this.$notify({
          title: '失败',
          message: '添加失败！',
          type: 'error'
        });

      })
    },
  },
};
</script>
